package com.chixing.controller;


import com.chixing.entity.BusinessOutlets;
import com.chixing.entity.BusinessOutletsES;
import com.chixing.service.EsBusinessOutletsService;
import com.chixing.service.IBusinessOutletsService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shy
 * @since 2022-10-31
 */
@RestController
@RequestMapping("/business-outlets")
public class BusinessOutletsController {
    @Resource
    private EsBusinessOutletsService esBusinessOutletsService;

    @Resource
    private IBusinessOutletsService businessOutletsService;

    @GetMapping("zsd/{id}")
    public void test1(@PathVariable("id") String id){
        System.out.println("===============================");
        BusinessOutlets byId = businessOutletsService.getById(id);
        List<BusinessOutlets> list = businessOutletsService.list();
        for (BusinessOutlets businessOutlets : list) {
            System.out.println(businessOutlets);
        }
        System.out.println("对象: "+byId);
    }

    @GetMapping("shyyhs")
    public void getList(){
        ArrayList<BusinessOutletsES> arrayList = new ArrayList<>();
        List<BusinessOutlets> list = businessOutletsService.list();
        for (BusinessOutlets businessOutlets : list) {
            BusinessOutletsES businessOutletsES = new BusinessOutletsES();
            businessOutletsES.setOutletsName(businessOutlets.getOutletsName());
            businessOutletsES.setOutletsId(businessOutlets.getOutletsId());
            businessOutletsES.setOutletsTel(businessOutlets.getOutletsTel());
            businessOutletsES.setOutletsStatus(businessOutlets.getOutletsStatus());
            businessOutletsES.setOutlesLocal(businessOutlets.getOutlesLocal());
            businessOutletsES.setOther1(businessOutlets.getOther1());
            businessOutletsES.setOther2(businessOutlets.getOther2());
            arrayList.add(businessOutletsES);

        }
        esBusinessOutletsService.saveAll(arrayList);
    }

    @GetMapping("/shydsb/{name}")
    public void getName(@PathVariable("name") String name){
        System.out.println("name: "+name);
        List<BusinessOutletsES> byoutletsName = esBusinessOutletsService.findByoutletsName(name);
        System.out.println(byoutletsName);
    }
}
